<template>
  <div id="CustomerOrderList">
    <div id="CustomerInfoList">
      <!--         Breadcrumbs -->
      <div class="breadcrumbs" style="margin: 0px;padding-top: 20px;">
        <ul>
          <li class="home"><a href="index.html" title="Go to Home Page"><strong style="font-size: 18px;">客户管理</strong></a>
            <span>/</span>
          </li>
          <li><strong>客户信息管理</strong><span>/</span></li>
          <li><strong>订单列表</strong></li>
        </ul>
      </div>
      <article class="col-main">
        <div class="my-account block block-account" style="padding-left: 20px;padding-right: 20px;">
          <div style="padding: 20px 20px 30px 20px">
            <span style="font-size: 30px;font-weight: bolder">订单列表</span>
            <div style="float: right;margin-top: 10px">
              <button v-on:click="toCreateCustomerOrder" class="btn btn-success">新建订单</button>
              <button v-on:click="toCustomerHistoricalOrderList" class="btn btn-primary">历史订单</button>
            </div>
          </div>
          <el-descriptions direction="vertical" :column="2" border>
            <el-descriptions-item label="客户编号">{{ customerId }}</el-descriptions-item>
            <el-descriptions-item label="客户名字">{{customerName}}</el-descriptions-item>
          </el-descriptions>
          <div style="border-bottom: #A7A7A7 2px solid;margin: 40px 0px"></div>
          <div v-show="orders ==''" class="alert alert-danger">
            没有正在进行的订单哦！
          </div>
          <div v-show="orders!=''">
            <table class="table">
              <thead>
              <tr>
                <th>订单编号</th>
                <th>客户</th>
                <th>送货地址</th>
                <th>状态</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody>
              <tr v-for="(item,index) in orders">
                <th>{{index+1+(current-1)*10}}</th>
                <td>{{item.customerName}}</td>
                <td>{{item.customerAddress}}</td>
                <td>
                  {{item.orderState}}
                </td>
                <td>
                  <button v-on:click="toUpdateCustomerOrder(item.orderId)" class="btn btn-default btn-sm">编辑</button>
                </td>
              </tr>
              </tbody>
            </table>
            <div class="block text-center">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
              </el-pagination>
            </div>
          </div>
          <div class="text-center" style="margin-top: 40px;padding-bottom: 30px">
            <button v-on:click="toCustomerDetailedInfo" class="btn btn-default btn-sm">返回</button>
          </div>
        </div>
      </article>
    </div>
  </div>
</template>

<script>
export default {
  name: "CustomerOrderList",
  data(){
    return{
      customerId:'',
      customerName:'',
      currentPage: 1,
      limit:10,
      current:1,
      total:0,
      orders:[]
    }
  },
  methods:{
    toCustomerHistoricalOrderList(){
      this.$router.push({path:'/MemuBar/CustomerHistoricalOrderList',query:{
          customerId:this.customerId,customerName:this.customerName
        }})
    },
    toUpdateCustomerOrder(orderId){
      this.$router.push({path:'/MemuBar/UpdateCustomerOrder',query:{
          customerId:this.customerId,customerName:this.customerName,orderId:orderId
        }})
    },
    toCreateCustomerOrder(){
      this.$router.push({path:'/MemuBar/CreateCustomerOrder',query:{
          customerId:this.customerId,customerName:this.customerName
        }})
    },
    toCustomerDetailedInfo(){
      this.$router.push({path:'/MemuBar/CustomerDetailedInfo',query:{
          customerId:this.customerId,customerName:this.customerName
        }})
    },
    loadCustomerIdAndName(){
      this.customerId=this.$route.query.customerId
      this.customerName=this.$route.query.customerName
    },
    handleSizeChange(val) {
      this.limit = val;
      this.loadOrders()
    },
    handleCurrentChange(val) {
      this.current = val;
      this.loadOrders()
    },
    loadOrders(){
      this.$axios.get('/order/loadOrders',{
        params:{
          limit:this.limit,
          current:this.current,
          customerId:this.$route.query.customerId
        }
      }).then(
        res=>{
          this.orders=res.data.data.myData
          console.log(this.orders)
          this.total=res.data.data.total
        }
      )
    }
  },
  created() {
    this.loadCustomerIdAndName()
    this.loadOrders()
  }
}
</script>

<style scoped>

</style>
